package com.example.zhu.controller;

import com.example.zhu.result.Result;
import com.example.zhu.service.MoneyService;
import com.example.zhu.vo.WithDrawVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/money")
@CrossOrigin
public class MoneyController {


    @Autowired
    private MoneyService moneyService;

    /**
     * 查询所有提现记录
     * @return
     */
    @GetMapping("check/All")
    public Result<List<WithDrawVO>> getWithdraw(){
        List<WithDrawVO> list = moneyService.getWithdraws();
        return Result.success(list);
    }

    /**
     * 更新提现状态,修改用户余额,生成交易记录
     * @return
     */
    @PutMapping("/check/{id}")
    public Result update(@PathVariable Integer id){
        //更新操作
        return moneyService.update(id);
    }

    /**
     * 根据id查询提现记录
     * @param id
     * @return
     */
    @GetMapping("check/one")
    public Result<WithDrawVO> getWithdraw(Integer id){
        WithDrawVO withDrawVO = moneyService.selectById(id);
        return Result.success(withDrawVO);
    }


    /**
     * 查询所有提现记录
     * @return
     */
    @GetMapping("check/phone")
    public Result<List<WithDrawVO>> getByPhone(@RequestParam String phone){
        List<WithDrawVO> list = moneyService.getByPhone(phone);
        return Result.success(list);
    }

    /**
     * 删除提现记录
     * @return
     */
    @DeleteMapping("check/{id}")
    public Result deleteById(@PathVariable Integer id){
        return moneyService.deleteById(id);
    }

}
